home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 106_01.zip / GRAVT100.C < prev    next >
Text File  |  1993-06-26  |  13KB  |  573 lines

  1. /*    graphics.c
  2.  
  3.     Version 3.0    29-May-80
  4.  
  5.       special CRT graphics functions are included in the
  6.     file GRAPHICS.CRL. this file contains most of the more
  7.     common functions of the terminal (VT100) itself as
  8.     well as a number of more general purpose drawing
  9.     functions. versions from 3.0 use the alternate ROM
  10.     character set.
  11.  
  12.         Function Summary
  13.         ----------------
  14.  
  15. 1. chrmode(mode)
  16.  
  17.     sets the character attributes. by convention these
  18.     are OFF,BOLD,UNDERLINE,BLINK,and REVERSE which are
  19.     defined as '0','1','4','5',and '7' respectively.
  20.  
  21. 2. clearl(mode)
  22.  
  23.     clears (erases) a line or part of a line according
  24.     to the mode. by convention these are TO_END,TO_CURSOR,
  25.     and ENTIRE which are defined as '0','1',and '2'
  26.     respectively.
  27.  
  28. 3. clears(mode)
  29.  
  30.     clears (erases) the screen (protocol as in 'clearl').
  31.  
  32. 4. clrallt()
  33.  
  34.     clears all tabs.
  35.  
  36. 5. clrtab()
  37.  
  38.     clear tab at current column.
  39.  
  40. 6. cursor(row,column)
  41.  
  42.     position cursor at the given coordinates.
  43.  
  44. 7. dheight(row,column,string)
  45.  
  46.     print the given string in double height (and double
  47.     width) characters at the given cursor position.
  48.  
  49. 8. diagbt(row,column,length,angle,scan_line)
  50.  
  51.     plot a diagonal line beginning at the given cursor
  52.     position from the bottom left to the top right of
  53.     the screen. by convention, the angles are ANGLE_30,
  54.     ANGLE_60 which are defined as 30,45,and 60 respectively.
  55.     scan_line is the initial line from which the diagonal
  56.     is drawn. these are given as follows:
  57.  
  58.     30 degrees bt: 10,8,5,3
  59.     30 degrees tb: 1,3,6,8
  60.     45 degrees bt: 10,5
  61.     45 degrees tb: 1,5
  62.     60 degrees bt: 10
  63.     60 degrees tb: 1
  64.  
  65.     the length is expressed as follows:
  66.  
  67.     30 degrees:    in 1/4 character slices
  68.     45 degrees:    in 1/2 character slices
  69.     60 degrees:    in one character slices
  70.     
  71.     the cursor comes to rest on the row that the next character
  72.     would be printed.
  73.  
  74. 9. diagtb(row,column,length,angle,scan_line)
  75.  
  76.     as in 'diagbt' but from the top right to the bottom
  77.     left of the screen.
  78.  
  79. 10. dwidth(row,column,string)
  80.  
  81.     print the given string in double width characters
  82.     at the given cursor position.
  83.  
  84. 11. entergraph(set)
  85.  
  86.     enter special graphics mode. by convention the character
  87.     sets are SET_UK,SET_0,SET_1,and SET_2 which are defined
  88.         as 'A','0','1',and '2' respectively.
  89.  
  90. 12. exitgraph()
  91.  
  92.     exit all graphics modes (ie. enter USASCII set).
  93.  
  94. 13. hline(row,column,length,scan_line)
  95.  
  96.     print a horizontal line of the specified length
  97.     beginning at the given cursor position. the line
  98.     is drawn on scan line which may be 1,3,5,7,9, or 10.
  99.  
  100. 14. horiz(row,column,length,character,mode)
  101.  
  102.     print a horizontal string of the specified character
  103.      beginning at the given cursor position in the
  104.     specified mode (character attribute(s)).
  105.  
  106. 15. index()
  107.  
  108.     cursor down one row (same column).
  109.  
  110. 16. leds(mode)
  111.  
  112.     turn the specified led(s) on or off. by convention
  113.     the modes are OFF,ON1,ON2,ON3,ON4 which are defined
  114.     as '0' through '4' respectively.
  115.  
  116. 17. movcur(direction,length)
  117.  
  118.     move the cursor in the specified direction the given
  119.     length. by convention the directions are UP,DOWN,
  120.     RIGHT,LEFT which are defined as 'A','B','C',and 'D'
  121.     respectively.
  122.  
  123. 18. normsize(row,column,string)
  124.  
  125.     print the given string in single height and single
  126.     width characters at the given cursor position.
  127.  
  128. 19. plot(row,column,character)
  129.  
  130.     plot the given character at the specified cursor position.
  131.  
  132. 20. plotgraph(row,column,character,set)
  133.  
  134.     plot the given character at the specified cursor position
  135.     using the specified character set (see entergraph).
  136.  
  137. 21. rindex()
  138.  
  139.     cursor up one row (same column).
  140.     
  141. 22. rstcur()
  142.  
  143.     restore cursor to previously saved position with saved
  144.     character attributes.
  145.  
  146. 23. savcur()
  147.  
  148.     save cuurent cursor position and character attributes.
  149.  
  150. 24. scroll(top,bottom)
  151.  
  152.     set boundaries of the scrolling region.
  153.  
  154. 25. setmode(mode)
  155.  
  156.     set/reset a terminal mode. the currently implemented
  157.     modes are NORMAL (80 columns), WIDE (132 columns),
  158.     BLACK (normal-black screen), WHITE (white screen),
  159.     KEYPAD (set keypad to function keys), NUMERIC (set
  160.     keypad to normal-numeric mode). these are defined
  161.     as '1' through '6' respectively.
  162.  
  163. 26. settab()
  164.  
  165.     set tab at current column.
  166.  
  167. 27. square(row,column,width,height,origin)
  168.  
  169.     plot a square or rectangle beginning at the given
  170.     cursor position with the specified width and height.
  171.     the origin is given as an integer as follows:
  172.  
  173.       ((scan_row * 10) + scan_column)
  174.  
  175.     possible origins:
  176.  
  177.       11:    scan_row 1,scan_column 1
  178.       14:   scan_row 1,scan_column 4
  179.       51:    scan_row 5,scan_column 1
  180.       54:   scan_row 5,scan_column 4
  181.  
  182. 28. txtplot(row,column,string)
  183.  
  184.     print the given string at the specified cursor position
  185.     with the given attributes mode (see chrmode).
  186.  
  187. 29. vert(row,column,length,character,mode)
  188.  
  189.     print a vertical string of the specified character
  190.     beginning at the given cursor position in the
  191.     specified mode (character attribute(s)).
  192.  
  193. 30. vline(row,column,length,scan_line)
  194.  
  195.     print a vertical line of the specified length
  196.     beginning at the given cursor position. the
  197.     line is drawn down scan_line which may be 1,4,or 7.
  198.  
  199. 31. extdig(plot)
  200.  
  201.     a dedicated sub-function not for general use.
  202.  
  203. */
  204. #define RESET 0
  205. #define ESC   27
  206.  
  207. #define    ANGLE_30    30
  208. #define    ANGLE_45    45
  209. #define    ANGLE_60    60
  210.  
  211. #define    OFF    '0'
  212. #define NORMAL  '1'
  213. #define WIDE    '2'
  214. #define BLACK   '3'
  215. #define WHITE   '4'
  216. #define KEYPAD  '5'
  217. #define NUMERIC '6'
  218. #define SET_UK  'A'
  219. #define SET_0    '0'
  220. #define SET_1    '1'
  221. #define SET_2    '2'
  222.  
  223. chrmode(mode)
  224. char(mode);
  225. {
  226.     putchar(ESC); putchar('[');
  227.     putchar(mode); putchar('m');
  228. }
  229.  
  230. clearl(mode)
  231. char mode;
  232. {
  233.     putchar(ESC); putchar('[');
  234.     putchar(mode); putchar('K');
  235. }
  236.  
  237. clears(mode)
  238. char mode;
  239. {
  240.     putchar(ESC); putchar('[');
  241.     putchar(mode); putchar('J');
  242. }
  243.  
  244. clrallt()
  245. {
  246.     putchar(ESC); puts("[3g");
  247. }
  248.  
  249. clrtab()
  250. {
  251.     putchar(ESC); puts("[g");
  252. }
  253.  
  254. cursor(row,column)
  255. int row, column;
  256. {
  257.     putchar(ESC); putchar('[');
  258.     extdig(row); putchar(';');
  259.     extdig(column); putchar('H');
  260. }
  261.  
  262. diagbt(row,column,length,angle,scan_line)
  263. int row, column, length, angle, scan_line;
  264. {
  265.     char diagstr[7];
  266.     int i;
  267.  
  268.     strcpy(diagstr,"GHIJ[\\\'"); cursor(row, column); entergraph(SET_1);
  269.     switch(angle) {
  270.       case ANGLE_30: switch(scan_line) {
  271.                case 10: i = 0; break;
  272.                case 8:  i = 1; break;
  273.                case 5:  i = 2; break;
  274.                case 3:  i = 3; break;
  275.                default: break;                
  276.              }
  277.              while (length--) {
  278.                putchar(diagstr[i]);
  279.                if (diagstr[i] == 'J') rindex();
  280.                if (i++ == 3) i = RESET;
  281.              }
  282.              break;
  283.       case ANGLE_45: if (scan_line == 10) i = 4;
  284.                else i = 5;
  285.              while (length--) {
  286.                putchar(diagstr[i]);
  287.                if (diagstr[i] == '\\') rindex();
  288.                if (i++ == 5) i = 4;
  289.              }
  290.              break;
  291.       case ANGLE_60: while (length--) { putchar(diagstr[6]); rindex(); }
  292.              break;
  293.       default:     break;
  294.     }
  295.     exitgraph();
  296. }
  297.  
  298. diagtb(row,column,length,angle,scan_line)
  299. int row, column, length, angle, scan_line;
  300. {
  301.     char diagstr[7];
  302.     int i;
  303.  
  304.     strcpy(diagstr,"CDEF]^("); cursor(row, column); entergraph(SET_1);
  305.     switch(angle) {
  306.       case ANGLE_30: switch(scan_line) {
  307.                case 1:  i = 0; break;
  308.                case 3:  i = 1; break;
  309.                case 6:  i = 2; break;                
  310.                case 8:  i = 3; break;
  311.                default: break;
  312.              }
  313.              while (length--) {
  314.                putchar(diagstr[i]);
  315.                if (diagstr[i] == 'F') index();
  316.                if (i++ == 3) i = RESET;
  317.              }
  318.              break;
  319.       case ANGLE_45: if (scan_line == 1) i = 4;
  320.                else i = 5;
  321.              while (length--) {
  322.                putchar(diagstr[i]);
  323.                if (diagstr[i] == '^') index();
  324.                if (i++ == 5) i = 4;
  325.              }
  326.              break;
  327.       case ANGLE_60: while (length--) { putchar(diagstr[6]); index(); }
  328.              break;
  329.       default:     break;
  330.     }
  331.     exitgraph();
  332. }
  333.  
  334. dheight(row,column,string)
  335. int row, column;
  336. char *string;
  337. {
  338.     cursor(row, column); savcur();
  339.     putchar(ESC); puts("#3"); puts(string);
  340.     rstcur(); index();
  341.     putchar(ESC); puts("#4"); puts(string);
  342. }
  343.  
  344. dwidth(row,column,string)
  345. int row, column;
  346. char *string;
  347. {
  348.     cursor(row, column);
  349.     putchar(ESC); puts("#6"); puts(string);
  350. }
  351.  
  352. entergraph(set)
  353. char set;
  354. {
  355.     putchar(ESC); putchar('('); putchar(set);
  356. }
  357.  
  358. exitgraph()
  359. {
  360.     putchar(ESC); puts("(B");
  361. }
  362.  
  363. hline(row,column,length,scan_line)
  364. int row, column, length, scan_line;
  365. {
  366.     int h_line, i;
  367.  
  368.     cursor(row, column);
  369.     switch(scan_line) {
  370.       case 1:       entergraph(SET_0); h_line = '\157'; break;
  371.       case 3:       entergraph(SET_0); h_line = '\160'; break;
  372.       case 5:       entergraph(SET_0); h_line = '\161'; break;
  373.       case 7:       entergraph(SET_0); h_line = '\162'; break;
  374.       case 9:       entergraph(SET_0); h_line = '\163'; break;
  375.       case 10:      entergraph(SET_2); h_line = '\137'; break;
  376.       default: break;
  377.     }
  378.  
  379.     for (i = RESET; i < length; ++i) putchar(h_line); /* horiz line */
  380.     exitgraph();
  381. }
  382.  
  383. horiz(row,column,length,character,mode)
  384. int row, column, length;
  385. char character, mode;
  386. {
  387.     int i;
  388.  
  389.     cursor(row, column); chrmode(mode);
  390.     for (i = RESET; i < length; ++i) putchar(character);
  391. }
  392.  
  393. index()
  394. {
  395.     putchar(ESC); putchar('D');
  396. }
  397.  
  398. leds(mode)
  399. char mode;
  400. {
  401.     putchar(ESC); putchar('[');
  402.     putchar(mode); putchar('q');
  403. }
  404.  
  405. movcur(direction,length)
  406. int length;
  407. char direction;
  408. {
  409.     putchar(ESC); putchar('['); extdig(length); putchar(direction);
  410. }
  411.  
  412. normsize(row,column,string)
  413. int row, column;
  414. char *string;
  415. {
  416.     cursor(row, column);
  417.     putchar(ESC); puts("#5"); puts(string);
  418. }
  419.  
  420. plot(row,column,character)
  421. int row, column;
  422. char character;
  423. {
  424.     cursor(row,column); putchar(character);
  425. }
  426.  
  427. plotgraph(row,column,character,set)
  428. int row,column;
  429. char character,set;
  430. {
  431.     entergraph(set); plot(row,column,character); exitgraph();
  432. }
  433.  
  434. rindex()
  435. {
  436.     putchar(ESC); putchar('M');
  437. }
  438.  
  439. rstcur()
  440. {
  441.     putchar(ESC); putchar('8');
  442. }
  443.  
  444. savcur()
  445. {
  446.     putchar(ESC); putchar('7');
  447. }
  448.  
  449. scroll(top,bottom)
  450. int top, bottom;
  451. {
  452.     putchar(ESC); putchar('[');
  453.     extdig(top); putchar(';');
  454.     extdig(bottom); putchar('r');
  455. }
  456.  
  457. setmode(mode)
  458. char mode;
  459. {
  460.     putchar(ESC);
  461.     switch(mode) {
  462.  
  463.     case NORMAL : puts("[?"); putchar('3'); putchar('l'); break;
  464.     case WIDE   : puts("[?"); putchar('3'); putchar('h'); break;
  465.     case BLACK  : puts("[?"); putchar('5'); putchar('l'); break;
  466.     case WHITE  : puts("[?"); putchar('5'); putchar('h'); break;
  467.     case KEYPAD : putchar('='); break;
  468.     case NUMERIC: putchar('>'); break;
  469.     }
  470. }
  471. settab()
  472. {
  473.     putchar(ESC); putchar('H');
  474. }
  475.  
  476. square(row,column,width,height,origin)
  477. int row, column, width, height, origin;
  478. {
  479.     char graph_mode;
  480.     int tl_corner, tr_corner, bl_corner, br_corner;
  481.     int h_line, v_line;
  482.     
  483.     switch(origin) {
  484.       case 11: graph_mode = SET_1; tl_corner = '\171'; tr_corner = '\172';
  485.            bl_corner = '\170'; br_corner = '\167'; h_line = 1;
  486.            v_line = 1; break;
  487.       case 14: graph_mode = SET_2; tl_corner = '\171'; tr_corner = '\170';
  488.            bl_corner = '\167'; br_corner = '\166'; h_line = 1;
  489.            v_line = 4; break;
  490.       case 51: graph_mode = SET_2; tl_corner = '\174'; tr_corner = '\175';
  491.            bl_corner = '\172'; br_corner = '\173'; h_line = 5;
  492.            v_line = 1; break;
  493.       case 54: graph_mode = SET_0; tl_corner = '\154'; tr_corner = '\153';
  494.            bl_corner = '\155'; br_corner = '\152'; h_line = 5;
  495.            v_line = 4; break;
  496.       default: break;    
  497.     }
  498.  
  499.     plotgraph(row,column,tl_corner,graph_mode);
  500.     hline(row,column+1,width-2,h_line);
  501.         plotgraph(row,column+width-1,tr_corner,graph_mode);
  502.         vline(row+1,column,height-2,v_line);
  503.     switch(origin) {
  504.       case 11: v_line = 7; h_line = 10; break;
  505.       case 14: h_line = 10; break;
  506.       case 51: v_line = 7; break;
  507.       default: break;
  508.     }
  509.  
  510.         vline(row+1,column+width-1,height-2,v_line);
  511.     plotgraph(row+height-1,column,bl_corner,graph_mode);
  512.        hline(row+height-1,column+1,width-2,h_line);
  513.      plotgraph(row+height-1,column+width-1,br_corner,graph_mode);
  514. }
  515.  
  516. txtplot(row,column,string,mode)
  517. int row,column;
  518. char *string, mode;
  519. {
  520.     cursor(row, column); chrmode(mode); puts(string);
  521. }
  522.  
  523. vert(row,column,length,character,mode)
  524. int row, column, length;
  525. char character, mode;
  526. {
  527.     cursor(row, column); chrmode(mode);
  528.  
  529.     int i;
  530.  
  531.     for (i = RESET; i < length; ++i) {
  532.     savcur(); putchar(character); rstcur(); index();
  533.     }
  534. }
  535.  
  536. vline(row,column,length,scan_line)
  537. int row, column, length, scan_line;
  538. {
  539.     int i, v_line;
  540.  
  541.     cursor(row, column);
  542.  
  543.     switch(scan_line) {
  544.       case 1:  v_line = '\144'; entergraph(SET_2); break;
  545.       case 4:  v_line = '\170'; entergraph(SET_0); break;
  546.       case 7:  v_line = '\150'; entergraph(SET_2); break;
  547.       default: break;
  548.     }
  549.  
  550.     for (i = RESET; i < length; ++i) {
  551.     savcur(); putchar(v_line); rstcur(); index();    /* vert line */
  552.     }
  553.     exitgraph();
  554. }
  555.  
  556. extdig(plot)
  557. int plot;
  558. {
  559.     int hundreds, tens, ones;
  560.  
  561.     hundreds = plot / 100; tens = (plot - (hundreds * 100)) / 10;
  562.     if (hundreds > 0) {
  563.        ones = (plot - (hundreds * 100)) % (tens * 10);
  564.        putchar(hundreds + '0');putchar(tens + '0');
  565.     }
  566.     else if (tens > 0) {
  567.        ones = plot % (tens * 10);
  568.        putchar(tens + '0');
  569.     }
  570.        else ones = plot;
  571.     putchar(ones + '0');
  572. }
  573.